package com.itheima.controller.admin;

import com.itheima.common.result.PageResult;
import com.itheima.common.result.Result;
import com.itheima.dto.YddAdvimgDTO;
import com.itheima.mapper.YddAdvimgMapper;
import com.itheima.mapper.YddAdvposMapper;
import com.itheima.pojo.YddAdvimg;
import com.itheima.service.IYddAdvimgService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class YddAdvimgController {
    @Autowired
    private YddAdvimgMapper yddAdvimgMapper;
    @Autowired
    private IYddAdvimgService yddAdvimgService;

    /**
     * 广告图详情
     * @param id
     * @return
     */
    @GetMapping("/ydd_advimg/rowInfo")
    public Result rowInfo(Integer id){

        return Result.success(yddAdvimgMapper.selectById(id));
    }

    /**
     * 广告图分页
     * @param dto
     * @return
     */
    @GetMapping("/ydd_advimg/list")
    public Result listAdvimg(YddAdvimgDTO dto){

        return Result.success(yddAdvimgService.listAdvimg(dto));
    }

    /**
     * 修改广告图
     * @param yddAdvimg
     * @return
     */
    @PostMapping("/ydd_advimg/update")
    public Result updateAdvimg(@RequestBody YddAdvimg yddAdvimg){
        yddAdvimgMapper.updateById(yddAdvimg);
        return Result.success();
    }

    /**
     * 删除广告图
     * @param id
     * @return
     */
    @GetMapping("/ydd_advimg/del")
    public Result deleteAdvimg(Integer id){
        yddAdvimgMapper.deleteById(id);
        return Result.success();
    }

    /**
     * 上传广告图
     * @param yddAdvimg
     * @return
     */
    @PostMapping("/ydd_advimg/add")
    public Result addAdvimg(@RequestBody YddAdvimg yddAdvimg){
        yddAdvimgMapper.insert(yddAdvimg);
        return Result.success();
    }

}
